<%-- 
  -- Body Select para Users
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>
<%@ taglib uri="/WEB-INF/displaytag-el.tld" prefix="display" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">

	function changeBody(radio) {
		$("selectedBodyId").value = radio.value;
	}
	
    function save() {
        var nameObj = $("modifyNameId");
        var passwordObj = $("modifyPasswordId");
        var realNameObj = $("modifyRealNameId");
        var surnameObj = $("modifySurnameId");
        var bodyObj = $("modifySelectedBodyId");
        var chosenRolesObj = $("modifyChosenRolesId");
        
        nameObj.value = $("userNameId").value;
        realNameObj.value = $("realNameId").value;
        surnameObj.value = $("surnameId").value;
        bodyObj.value = $("selectedBodyId").value;
        chosenRolesObj.value = $("chosenRolesId").value;
        passwordObj.value = $("passwordId").value;
        
        var form = $("modifyUserFormId");
        form.submit();
    }
  </script>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/selectBody.do" styleId="userFormId">
	<html:hidden property="password" styleId="passwordId" />
	<html:hidden property="realName" styleId="realNameId" />
	<html:hidden property="surname" styleId="surnameId" />
	<html:hidden property="chosenRoles" styleId="chosenRolesId" />
	
    <%-- Inyectados por Javascript --%>
    <h2>Modificaci&oacute;n de Usuario</h2>
    <p>Elija el ente al cual pertenece el usuario</p>
    <br/>
    <div class="userBody">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Usuario &nbsp;
                </td>
                <td class="tableDataValue">
				    <html:text readonly="true" property="name" styleId="userNameId" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    &nbsp;
                </td>
                <td class="tableDataValue">
				    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Entes
                </td>
                <td class="tableDataValue">
                
            	<html:hidden styleId="selectedBodyId" property="selectedBody" />
            	<bean:define id="allBodies" name="userForm" property="bodies" />
            	
            	<logic:notEmpty name="userForm" property="bodies">
	                <logic:iterate id="body" name="allBodies">
	                    <bean:define id="bodyId">
	                    	<bean:write name="body" property="id" />
			            </bean:define>
			            <p class="bodyItem">
			            <bean:define id="bodyName">
	                    	<bean:write name="body" property="name" />
			            </bean:define>
	        		    <html:radio property="selectedBody" value="<%=bodyId%>" onclick="javascript:changeBody(this)" />
	            		<bean:write name="bodyName"/>
	            		</p>
	                </logic:iterate>
                </logic:notEmpty>
                
                <logic:empty name="userForm" property="bodies">
                	<p>Debe dar de alta alg&uacute;n Ente para poder asignar uno a este Usuario.</p>
                	<p>No se puede continuar con el alta del presente usuario.</p>
                </logic:empty>
                
                </td>
            </tr>
        </table>
        <logic:notEmpty name="userForm" property="bodies">
        <div class="panelButton">
			<input type="button" onClick="save();" title="Guardar el usuario..." value="Guardar" class="button" />
		</div>
		</logic:notEmpty>
    </div>
</html:form>

<%-- Inyectados por Javascript --%>
<div id="modifyUserDivId" class="hideClass">
    <html:form action="/protected/saveUser" styleId="modifyUserFormId">
        <html:hidden property="name" value="" styleId="modifyNameId" />
        <html:hidden property="password" value="" styleId="modifyPasswordId" />
        <html:hidden property="selectedBody" value="" styleId="modifySelectedBodyId" />
        <html:hidden property="chosenRoles" value="" styleId="modifyChosenRolesId" />
        <html:hidden property="realName" value="" styleId="modifyRealNameId" />
        <html:hidden property="surname" value="" styleId="modifySurnameId" />
    </html:form>
</div>    
